package com.itheima.service.impl;

import com.itheima.dao.MedicalUploadDao;
import com.itheima.service.MedicalUploadService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author yangsen
 * @desc
 * @Date 2020/10/30 18:19
 */
@Service
@Transactional
public class MedicalUploadServiceImpl implements MedicalUploadService {


    @Autowired
    private MedicalUploadDao medicalUploadDao;

    /**
     * 文件上传成功后向数据库添加数据
     *
     * @param healthURL   体检报告的url地址
     * @param id         会员的id
     * @param fileNumber 会员的编号
     */
    @Override
    public void add(String healthURL, String id, String fileNumber) {

        //向数据库添加
        medicalUploadDao.add(healthURL,id,fileNumber);
    }



    /**
     * 通过会员的id查询出体检报告的文段地址云端
     *
     * @param id 会员的id
     * @return 云端的地址
     */
    @Override
    public List<String> getHealthURL(Integer id) {
        List<String> list = medicalUploadDao.getHealthURL(id);

        if (list.size() == 0 ){
            //表示没有他的体检信息,抛异常
           throw new RuntimeException("该用户没有体检信息");
        }

        return list;

    }


    /**
     * 删除数据库的地址，同时返回云端地址
     *
     * @param id 删除的会员的id
     */
    @Override
    public void delete(Integer id) {
        medicalUploadDao.delete(id);
    }

}
